<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
      function Studance(name,age) {
      this.name = name;
      this.age = age;
      // this.type = "bus";
      this.fuu = function () {
        console.log(this.name);
      }
    }
    // 原型对象上增加的属性和方法是共享的
    Studance.prototype.type = "bbs";
    Studance.prototype.fan =  function () {
        console.log(this.age);
      }
        var st1 = new Studance("试试",115);
        var st2 = new Studance("自杀",112);
    st2.fan();
    console.log(st2);//Studance

    var s1 = st2.__proto__//指向的是Studance的原型对象
    console.log(s1);
    // 任何一个函数都有__proto__

    var ss1 = s1.__proto__;
    console.log(ss1);
    console.log(ss1.constructor);

    var sss = ss1.__proto__;//null
    console.log(sss);

    // 就近原则，先在自身上查找-----重点
      // 如果自身上有就用自身的，如果没有就往原型对象上查找
      // 如果原型没有，就按原型连往上查找,直到查找到null停止查找，返回undefined
      // 避免原型链过长


    st1.fuu();
    console.log(st1.fuu);
    console.log(st1.func);//undefined
    console.log(st1.valueOf());//object的方法
  </script>
</body>
</html>